$(document).ready(function () {
    var $container = $('#product_list');

    $container.isotope({
        itemSelector: '.item',
        layoutMode: 'fitRows'
    });
    /*
    $('#filters a').click(function () {
    $('#filters a.active').removeClass('active');
    $(this).addClass('active');
    var selector = $(this).attr('data-filter');
    $container.isotope({
    filter: selector
    });
    return false;
    });
    */
    $('#menu li.menu-item').click(function () {
        if ($(this).hasClass('selected')) {
            return false;
        }

        $('#menu li.selected').removeClass('selected');
        $(this).addClass('selected');
        var data;
        if ($(this).hasClass('author')) {
            data = 'author';
        }
        else {
            data = 'product';
        }
        $.post("indexController.aspx", { page: data },
         function (data) {
             var rs = data.split('~');

             $('#filters').html(rs[0]);
             $('#product_list').html(rs[1]);
         });


        return false;
    });
    $('#info-wrapper').hover(function () {

        //$('#cart-content').animate({height: '400'}, 100);
        $('#cart-content').css({ height: '100%' }).animate(400);
    }, function () {
        $('#cart-content').animate({ height: '0' }, 300);
    });



    $('.add2Cart').click(function () {
        var idProduct = $(this).attr('id');
        var price = parseInt($(this).parent().children('.price').html());
        var total = parseInt($('span#total').html());
        $.ajax({
            type: 'post',
            url: 'shoppingcart.aspx',
            data: 'type=add&idProduct=' + idProduct,
            success: function (status) {
                if (status == "ok") {
                    var html = '<dt id="cart_block_product" > '
                    + '<a class="cart_block_product_name" href="#" title="Collant - Aqua blue">' + $('span.name').html() + '</a> '
                    + '<span class="taille_cho7">' + idProduct + '</span> '
                    + '<span class="quantity-formated">'
                    + '<span class="quantity">1</span>'
                    + '</span> '
                    + '<span class="price">' + price + '</span> '
                    + '<span class="remove_link"><a href="#">X</a></span> '
                    + '<span class="spacer_panier"></span>'
                    + '</dt>';

                    total += price;
                    $('span#total').html(total);
                    $('dl.products').append(html);
                    $('.ajax_cart_quantity').html(parseInt($('.ajax_cart_quantity').html()) + 1);
                }
            }
        });

        return false;
    });


    $('ul#list-img li img').click(function () {
        var src = $(this).attr('src');
        $('#img-main img').fadeOut('slow', function () { $('#img-main img').attr('src', src); });

        $('#img-main img').fadeIn(500);

    });


    $('#button_order_cart').click(function () {

    });

    $(document).on("click", "#filters a", function () {
        

        $('#filters a.active').removeClass('active');
        $(this).addClass('active');
        var selector = $(this).attr('data-filter');
        $container.isotope({
            filter: selector
        });
        return false;
    });
});

$(document).on("click", ".remove_link", function () {
    var idProduct = $('span.taille_cho7', $(this).parent()).html();
    $(this).parent().remove();
    $.ajax({
        type: 'post',
        url: 'shoppingcart.aspx',
        data: 'type=remove&idProduct=' + idProduct,
        success: function (status) {
            var total = parseInt($('span#total').html());
            var price = parseInt($(this).parent().children('.price').html());
            total -= price;
            $('span#total').html(total);
            $('.ajax_cart_quantity').html(parseInt($('.ajax_cart_quantity').html()) - 1);
        }
    });


});

